//designpatterns.prototype.deepclone.Client.java
package org.patterns.creational.prototype.deepclone;


public class Client {
    public static void main(String[] args) {
        WeeklyLog log_previous, log_new = null;
        log_previous = new WeeklyLog();
        log_previous.setName("王阳明");
        log_previous.setDate("第16周");
        log_previous.setContent("这周工作很忙，每天加班！");//创建原型对象
        Attachment attachment = new Attachment();   //创建附件对象
        log_previous.setAttachment(attachment);     //将附件添加到周报中

        System.out.println("****周报****");
        System.out.println("周次：" + log_previous.getDate());
        System.out.println("姓名：" + log_previous.getName());
        System.out.println("内容：" + log_previous.getContent());
        System.out.println("--------------------------------");

        try {
            log_new = log_previous.deepClone(); //调用深克隆方法创建克隆对象
            log_new.setDate("第17周");
            System.out.println("****周报****");
            System.out.println("周次：" + log_new.getDate());
            System.out.println("姓名：" + log_new.getName());
            System.out.println("内容：" + log_new.getContent());
            System.out.println("--------------------------------");
        } catch (Exception e) {
            System.err.println("克隆失败！");
        }

        //比较周报
        System.out.println("周报是否相同？ " + (log_previous == log_new));
        System.out.println("日期是否相同？ " + (log_previous.getDate() == log_new.getDate()));
        System.out.println("姓名是否相同？ " + (log_previous.getName() == log_new.getName()));
        System.out.println("内容是否相同？ " + (log_previous.getContent() == log_new.getContent()));
        //比较附件
        System.out.println("附件是否相同？ " + (log_previous.getAttachment() == log_new.getAttachment()));
    }
}